﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.IO;
using System.Diagnostics;


namespace CamPlug
{
	[RunInstaller(true)]
	public partial class RegisterLibrary : System.Configuration.Install.Installer
	{
		public RegisterLibrary()
		{
			InitializeComponent();
		}

		[SecurityPermission(SecurityAction.Demand)]
		public override void Commit(IDictionary savedState)
		{
			base.Commit(savedState);

			string regAsmPath = Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), "regasm.exe");
			string libraryPath = typeof(RegisterLibrary).Assembly.Location;
			string libraryTlbPath = Path.ChangeExtension(libraryPath, ".tlb");
			string parameters = string.Format(@"""{0}"" /nologo /codebase /tlb: ""{1}""", libraryPath, libraryTlbPath);
			Process.Start(regAsmPath, parameters);
		}

		[SecurityPermission(SecurityAction.Demand)]
		public override void Install(IDictionary stateSaver)
		{
			base.Install(stateSaver);
		}

		[SecurityPermission(SecurityAction.Demand)]
		public override void Uninstall(IDictionary savedState)
		{
			string regAsmPath = Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), "regasm.exe");
			string libraryPath = typeof(RegisterLibrary).Assembly.Location;
			string libraryTlbPath = Path.ChangeExtension(libraryPath, ".tlb");
			string parameters = string.Format(@"""{0}"" /nologo /codebase /tlb: ""{1}""", libraryPath, libraryTlbPath);
			Process.Start(regAsmPath, parameters);
			base.Uninstall(savedState);
		}
	}
}
